//
//  FontSizeView.m
//  JW_BasePorject
//
//  Created by JW on 2018/7/4.
//  Copyright © 2018年 JW. All rights reserved.
//

#import "FontSizeView.h"

@interface FontSizeView ()

@property (nonatomic,copy)fontBlock clickBlock;

@property (nonatomic,weak)UIButton *selectedBtn;

@end

@implementation FontSizeView

- (instancetype)initWithClickAction:(fontBlock)clickBlock{
    self = [super initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    if (self) {
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 70, 30)];
        titleLabel.text = @"字体大小";
        [self addSubview:titleLabel];
        
        UIButton *fontMax = [self creatButtonWithFrame:CGRectMake(SCREEN_WIDTH - 40, 10, 30, 30) fontSize:18];
        [self addSubview:fontMax];
        
        UIButton *midBtn = [self creatButtonWithFrame:CGRectMake(CGRectGetMinX(fontMax.frame) -30-30, 10, 30, 30) fontSize:16];
        [self addSubview:midBtn];
        
        UIButton *minBtn = [self creatButtonWithFrame:CGRectMake(CGRectGetMinX(midBtn.frame) -30-30, 10, 30, 30) fontSize:14];
        [self addSubview:minBtn];
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, 49.5, SCREEN_WIDTH - 20, 0.5)];
        line.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:line];
        
        self.clickBlock = clickBlock;
        
    }
    return self;
}

- (void)btn_click:(UIButton *)sender{
    
    _selectedBtn.selected = NO;
    sender.selected = YES;
    _selectedBtn = sender;
    
    if (self.clickBlock) {
        self.clickBlock(sender);
    }
    
}

- (UIButton *)creatButtonWithFrame:(CGRect)frame fontSize:(CGFloat)fontSize{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    [btn setTitle:@"Aa" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    [btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:ZhuTiColor forState:UIControlStateSelected];
    
    [btn addTarget:self action:@selector(btn_click:) forControlEvents:UIControlEventTouchUpInside];
    
    return btn;
}

@end
